package cn.yunlang.zhangZhongFei.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import cn.yunlang.zhangZhongFei.entity.Information;
import cn.yunlang.zhangZhongFei.service.InformationService;
import cn.yunlang.zhangZhongFei.vo.response.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/Information")
@Api(tags = "首页资讯")
public class InformationController {

  @Resource private InformationService informationService;

  @ApiOperation("全查")
  @GetMapping("/list")
  public R<List<Information>> list() {
    return informationService.listAll();
  }

  @ApiOperation("分页查询资讯")
  @GetMapping("/page")
  public R<IPage<Information>> page(
      @ApiParam(value = "页码", required = true) @RequestParam Integer pageNo,
      @ApiParam(value = "每页大小", required = true) @RequestParam Integer pageSize,
      @ApiParam(value = "标题", required = false) @RequestParam(required = false) String title) {
    return informationService.pageInfo(pageNo, pageSize, title);
  }

  @GetMapping("/one")
  @ApiOperation("根据Id查一条")
  public R<Information> one(@RequestParam Long informationId) {
    return informationService.getOne(informationId);
  }

  @PostMapping("/add")
  @ApiOperation("新增")
  public R<String> add(@RequestBody Information information) {
    return informationService.addInfo(information);
  }

  @GetMapping("/delete")
  @ApiOperation("删除")
  public R<String> delete(@RequestParam Long informationId) {
    return informationService.deleteInfo(informationId);
  }

  @PostMapping("/update")
  @ApiOperation("修改")
  public R<String> update(@RequestBody Information information) {
    return informationService.updateInfo(information);
  }
}
